package com.plant.consult.controller;

import com.plant.common.domain.User;
import com.plant.common.result.Result;
import com.plant.consult.domain.*;
import com.plant.consult.service.ConsultDetailService;
import com.plant.consult.service.ConsultRecordService;
import com.plant.consult.service.ConsultService;

import com.plant.consult.service.impl.ConsultRecordServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
*  问诊模块
*/
@RestController
@RequestMapping("consult")
public class ConsultController {
    @Autowired
    private ConsultService consultService;
    @Autowired
    private ConsultRecordService consultRecordService;
    @Autowired
    private ConsultDetailService consultDetailService;
    @PostMapping("/add")
    public Result add(@RequestBody Consult consult) {
       Consult consult1= consultService.add(consult);
        return Result.ok(consult1);
    }
    @PostMapping("/money")
    public Result money(@RequestBody Consult consult) {
        consultService.money(consult);
        return Result.ok();
    }
    @GetMapping("/list")
    public Result list() {
        List<Consult> list = consultService.list();
        return Result.ok(list);
    }
    @GetMapping("/findUserId/{userId}")
    public Result findUserId(@PathVariable Integer userId) {
        List<Consult> list = consultService.userIdList(userId);
        return Result.ok(list);
    }
    @PostMapping("/insertRecord")
    public Result insertRecord(@RequestBody ConsultRecord consultRecord) {
        Integer id= consultRecordService.insert(consultRecord);
        return Result.ok(id);
    }
    @PostMapping("/insertDetail")
    public Result insertDetail(@RequestBody ConsultDetail consultDetail) {
        System.out.println(consultDetail);
        consultDetailService.insert(consultDetail);
        return Result.ok();
    }

    @GetMapping("/Number/{phId}")
    public Result number(@PathVariable Integer phId) {
        String mag= consultRecordService.findUserId(phId);
        return Result.ok(mag);
    }
    @GetMapping("/myConsultation")
    public Result myConsultation(@RequestParam Integer userId, Integer type) {
        User user = new User();
        user.setId(userId);
        user.setType(type);
        if(user.getType()==1 || user.getType()==3){
            List<Consult> list= consultService.oneList(user);
            return Result.ok(list);
        }else if(user.getType()==2){
            List<Consult> list= consultService.userIdList(user.getId());
            return Result.ok(list);
        }
        return Result.ok();
    }
//    回复查询
    @PostMapping("/Reply")
    public Result Reply(@RequestBody ConsultDetail consultDetail) {
       ConsultVo list= consultService.ReplyList(consultDetail);
        return Result.ok(list);
    }
//    回复添加
    @PostMapping("/ReplyAdd")
    public Result Reply(@RequestBody ConsultDetailDto consultDetailVo) {
        consultDetailService.replyAdd(consultDetailVo);
        return Result.ok();
    }
//    结束问诊
    @PostMapping("/updateStatus")
    public Result endConsult(@RequestBody Consult consult) {
        consultService.update(consult);
        return Result.ok();
    }
//    查询问诊记录
    @PostMapping("/selectReply")
    public Result selectReply(@RequestBody Consult consult) {
        List<ConsultRecord> list= consultRecordService.selectReply(consult);
        return Result.ok(list);
    }
    @GetMapping("/backgroundRecord")
    public Result backgroundRecord() {
        List<BackgroundRecordVo> list= consultRecordService.backgroundRecordSelect();
        return Result.ok(list);
    }
    @PostMapping("/ReplyById")
    public Result ReplyById(@RequestBody Consult consult){
      List<ConsultDetail> list =  consultDetailService.ReplyById(consult);
      return Result.ok(list);
    }

}
